
-- EliteMatchTeamPanel 精英决斗赛队伍面板

local NewTeamMemberInfoPanel = require("app.team.views.NewTeamMemberInfoPanel")
local TeamMemberInfoVo = require("app.team.models.TeamMemberInfoVo")

local EliteMatchTeamPanel = app.mvc.createPanelClass(...)

local teamMemberNum = 5 -- 队伍最大人数

function EliteMatchTeamPanel.createWithData(data, node)
    local sprite = EliteMatchTeamPanel.extend(node or cc.CSLoader:createNode(Res.NewMemberInfoNode))
    if node == nil then
        ccui.Helper:doLayout(sprite)
    end
    sprite:init()
    return sprite
end

function EliteMatchTeamPanel.create(node)
    return EliteMatchTeamPanel.createWithData(nil ,node)
end

function EliteMatchTeamPanel:init(data)
    self.super.init(self, data)

    -- 普通队伍成员信息
	self.teamMemberInfoList = {}
	for i = 1, teamMemberNum do
		local infoTemp = NewTeamMemberInfoPanel.create(self._ui["Panel_team/player0"..i])
		infoTemp:setData( nil )
		infoTemp:registerOnOperate(function(op, ...)
					executeFunc(self._onOperate, op, ...) -- 交由controller处理
				end)
		table.insert( self.teamMemberInfoList, infoTemp )
    end
    
    self._ui.Panel_legion:setVisible(false)
end

function EliteMatchTeamPanel:refresh()
    if self._data then
        local data = self._data
        -- 第一个是玩家自身
        local myinfo = {}
        myinfo.userBaseInfo = data:getUserDataBaseInfo()
        myinfo.isLeader = true
        local member = TeamMemberInfoVo.new(myinfo)
        self.teamMemberInfoList[1]:setData(member) -- UserBaseInfo
        self.teamMemberInfoList[1]:refreshTeamLeaderFlag(false)
        -- 后面都是上阵随从
        local partnerInfos = data:getPartnerInfos()
        local count = 1
        for i = 2, teamMemberNum do
            self.teamMemberInfoList[i]:setData(nil)
            self.teamMemberInfoList[i]:setTips(L("EliteMatchTip23"))
            if partnerInfos[count] then
                local partnerInfo = UD.partnersData:getPartnerById(partnerInfos[count].id)
                self.teamMemberInfoList[i]:setPartnerInfo(partnerInfo)
                self.teamMemberInfoList[i]:setReadyStatus(false)
            end
            self.teamMemberInfoList[i]:setIsOnBattlePartner(true)
            count = count + 1
        end
    end
end

function EliteMatchTeamPanel:registerOnOperate(cb)
    self._onOperate = cb
end

return EliteMatchTeamPanel